<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <button id="getToken">getToken</button>
    <button id="requestAPI">requestAPI</button>

    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <script>
    $(function () {
      var accessToken = undefined;

      $("#getToken").click(function () {
        $.post(
          "/api/TokenAuth",
          { Username: "user1", Password: "user1psd" },
          function (data) {
            console.log(data);
            if (data.stateCode == 1)
            {
              accessToken = data.accessToken;

              $.ajaxSetup({
                headers: { "Authorization": "Bearer " + accessToken }
              });
            }
          },
          "json"
        );
      })

      $("#requestAPI").click(function () {
        $.get("/api/Values", {}, function (data) {
          alert(data);
        }, "text");
      })
    })
    </script>
</body>
</html>